package com.xxx.store.utils;

import java.util.HashMap;

public class Result extends HashMap<String, Object> {
    public Result() {
        this.put("code", 0);
    }

    public static Result ok(String msg, Object data) {
        Result result = new Result();
        result.put("msg", msg);
        result.put("data", data);
        return result;
    }

    public static Result ok(Object data) {
        return Result.ok("请求成功", data);
    }

    public static Result ok(String msg) {
        return Result.ok(msg, null);
    }

    public static Result ok() {
        return Result.ok("请求成功", null);
    }


    public static Result error(String msg, Object data) {
        Result result = new Result();
        result.put("code", 500);
        result.put("msg", msg);
        result.put("data", data);
        return result;
    }

    public static Result error(String msg) {
        return Result.error(msg, null);
    }

    public static Result error() {
        return Result.error("请求失败", null);
    }

    @Override
    public Result put(String key, Object value) {
        super.put(key, value);
        return this;
    }
}
